$(document).ready(function(){
    var $province = $('#province');
    var $city= $('#city');
    var $region= $('#region');

    if(!EOVA_FORM)
        return;

    var cmbProvince = $province.eovacombo();
    var cmbCity = $city.eovacombo();
    var cmbRegion = $region.eovacombo();

    // 初始禁用
    cmbCity.readonly(true);
    cmbRegion.readonly(true);
    if($province != ""){
        cmbCity.readonly(false);
        $city.eovacombo({exp : 'selectAreaByLv2AndPid,' + 25}).reload();
    }

    // 省级联市
    $province.eovacombo({onChange: function (oldValue, newValue) {
            cmbCity.setValue("");
            cmbRegion.setValue("");

            if (newValue == "") {
                cmbCity.readonly(true);
                return;
            }
            cmbCity.readonly(false);

            $city.eovacombo({exp : 'selectAreaByLv2AndPid,' + newValue}).reload();
        }});
    // 市级联区县
    $city.eovacombo({onChange: function (oldValue, newValue) {
            cmbRegion.setValue("");

            if (newValue == "") {
                cmbRegion.readonly(true);
                return;
            }
            cmbRegion.readonly(false);
            $region.eovacombo({exp : 'selectAreaByLv3AndPid,' + newValue}).reload();

        }});

    var $corporation = $('#corporation');
    var $company = $('#company');
    var $department= $('#department');

    if(!EOVA_FORM)
        return;

    var cmbCorporation = $corporation.eovacombo();
    var cmbCompany = $company.eovacombo();
    var cmbDepartment = $department.eovacombo();

    // 初始禁用
    cmbCompany.readonly(true);
    cmbDepartment.readonly(true);
    if($corporation !=""){
        cmbCompany.readonly(false);
        $company.eovacombo({exp : 'selectOrgByLv2AndPid,' + 20000000}).reload();
    }


    // 省级联市
    $corporation.eovacombo({onChange: function (oldValue, newValue) {
            cmbCompany.setValue("");
            cmbDepartment.setValue("");
            if (newValue == "") {
                cmbCompany.readonly(true)
                return;
            }
            cmbCompany.readonly(false);
            $company.eovacombo({exp : 'selectOrgByLv2AndPid,' + newValue}).reload();
        }});

    // 省级联市
    $company.eovacombo({onChange: function (oldValue, newValue) {
            cmbDepartment.setValue("");
            if (newValue == "") {
                cmbDepartment.readonly(true);
                return;
            }
            cmbDepartment.readonly(false);
            $department.eovacombo({exp : 'selectOrgByLv3AndPid,' + newValue}).reload();
        }});

});